package com.yc.booktable.web;
import com.yc.booktable.entity.AdminUser;
import com.yc.booktable.entity.Bookinfo;
import com.yc.booktable.entity.Feedback;
import com.yc.booktable.mapper.FeedbackMapper;
import com.yc.booktable.service.impl.FeedbackServiceImpl;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.net.HttpCookie;
import java.util.List;

@Controller
public class feedbackAction {
    @Resource
    private FeedbackMapper feedbackMapper;
    @Resource
    private FeedbackServiceImpl feedbackService;

    @RequestMapping("icons")
    public String String (Model model, HttpSession session){
        AdminUser user = (AdminUser) session.getAttribute("loginedUser");
        if(user==null|| user.getState()==1){
            return "redirect:/login";
        }
        model.addAttribute("user",user);
        List<Feedback> feedbacks = feedbackMapper.selectList(null);
        model.addAttribute("feedback",feedbacks);
        return "icons";
    }
    @RequestMapping("/deletefb/{kid}")
    public String move(@PathVariable("kid") int kid){
        try {
            System.out.println("删除");
            feedbackService.removeById(kid);
            return "redirect:/icons";
        } catch ( Exception e){
            e.printStackTrace();
            return "error";
        }
    }
    /**
     * 处理回复
     */
    /*@GetMapping("/queryfd")
    public String queryf(Integer id,Model model){
        Feedback fd = feedbackService.getById(id);
        model.addAttribute("fd",fd);
        return "deal";
    }
    @PostMapping("updatefd")
    public String update(Feedback fd){
        fd.setFstatus(1);
        feedbackService.saveOrUpdate(fd);
        return "redirect:/typography";
    }*/
    @GetMapping("/queryfd")
    public String querybi(Integer id,Model model){
        Feedback fd = feedbackService.getById(id);
        model.addAttribute("fd",fd);
        return "dealfd";
    }
    @PostMapping("updatefd")
    public String update(Feedback fd){
        fd.setFstatus(1);
        feedbackService.saveOrUpdate(fd);
        return "redirect:/icons";
    }
}
